package com.hqyj.freemovie.front.test;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CountDownLatch;

public class HashMapDemo {

    public static void main(String[] args) throws InterruptedException {


        //Map<Integer, Integer> map = new HashMap<>();
        Map<Integer, Integer> map = new ConcurrentHashMap<>();

        CountDownLatch countDownLatch = new CountDownLatch(4);

        new Thread(() -> {
            for (int i = 0; i < 1000; i++) {
                map.put(i, i);
            }
            countDownLatch.countDown();
        }).start();

        new Thread(() -> {
            for (int i = 1000; i < 2000; i++) {
                map.put(i, i);
            }
            countDownLatch.countDown();
        }).start();

        new Thread(() -> {
            for (int i = 2000; i < 3000; i++) {
                map.put(i, i);
            }
            countDownLatch.countDown();
        }).start();

        new Thread(() -> {
            for (int i = 3000; i < 4000; i++) {
                map.put(i, i);
            }
            countDownLatch.countDown();
        }).start();

        countDownLatch.await();
        System.out.println(map.size());

    }
}
